package greatwall.myreader;

import java.util.List;

import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.opengl.Visibility;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextPaint;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.ToggleButton;
import com.iximo.domain.*;

public class ReadBookActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setTitle("samoolActivity");
	setContentView(R.layout.read_interface);
	
	GetControls();
	SetControlsValueAndListener();
	}
	
	//Activity中的控件
	private SeekBar mChangeFontSize; 			//改变字体大小的拖动条
	private EditText mContent;				//图书内容
	private ToggleButton mChangeFontBold;	//改变字体是否加粗
	private ToggleButton mChangeFontLine;	//改变字体下划线
	private Button mReadMenu;
	private Button mFont;
	private Button mLight;
	private Button mReadSearch;
	private Button mAutoNextPage;
	private FrameLayout mLayoutFont;
	private FrameLayout mLayoutLight;
	private FrameLayout mLayoutSearch;
	//获取Activity中的控件
	private void GetControls()
	{
		mChangeFontSize = (SeekBar)findViewById(R.id.readbook_changefont);
		mContent = (EditText)findViewById(R.id.readbook_content);
		mChangeFontBold = (ToggleButton)findViewById(R.id.toggleButton1);
		mChangeFontLine = (ToggleButton)findViewById(R.id.toggleButton2);
		mReadMenu = (Button)findViewById(R.id.read_menu);
		mFont = (Button)findViewById(R.id.size);
		mLight = (Button)findViewById(R.id.light);		
		mReadSearch = (Button)findViewById(R.id.read_search);
		mAutoNextPage = (Button)findViewById(R.id.auto_nextpage);
		mLayoutFont = (FrameLayout)findViewById(R.id.frameLayoutFont);
		mLayoutLight = (FrameLayout)findViewById(R.id.frameLayoutLight);
		mLayoutSearch = (FrameLayout)findViewById(R.id.frameLayoutSearch);
	}
	
	//设置按钮点击监听事件
	private void SetControlsValueAndListener()
	{		
		mChangeFontSize.setMax(100);
		mChangeFontSize.setProgress(30);		
		mChangeFontSize.setOnSeekBarChangeListener(sbLis);
		
		mContent.setTextSize(18f);
		
		mContent.setSelection(0);
		
		mContent.requestFocus();
		//不弹出软键盘
		//mContent.setInputType(InputType.TYPE_NULL);
		//测试数据
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < 500; i++)
		{
			sb.append("这是测试数据");
		}
		mContent.setText(sb.toString());
		
		mChangeFontBold.setOnCheckedChangeListener(tb1Lis);
		mChangeFontLine.setOnCheckedChangeListener(tb1Lis);
		
		mFont.setOnClickListener(bList);
		mLight.setOnClickListener(bList);
		mReadSearch.setOnClickListener(bList);
		
	}
	
	private android.view.View.OnClickListener bList = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			mLayoutFont.setVisibility(8);
			mLayoutLight.setVisibility(8);
			mLayoutSearch.setVisibility(8);
			if(v == mFont)
			{
				mLayoutFont.setVisibility(0);
			Log.i("KeaneWang", "aa");
			}
			if(v == mLight)
			{
				mLayoutLight.setVisibility(0);
				Log.i("KeaneWang", "bb");
			}
			if(v == mReadSearch)
			{
				mLayoutSearch.setVisibility(0);
				Log.i("KeaneWang", "cc");
			}
			//Log.i("KeaneWang", "dd");
		}
	};
	
	
	
	
	private OnCheckedChangeListener tb1Lis = new OnCheckedChangeListener() {
		
		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			
			// TODO Auto-generated method stub
			TextPaint tp = new TextPaint();
			tp = mContent.getPaint();
			if(buttonView == mChangeFontBold)
			{
				tp.setFakeBoldText(isChecked);
				
			}
			else
			{
				tp.setUnderlineText(isChecked);
			}
			mContent.setSelection(mContent.getSelectionStart());			
		}
	};
	private OnSeekBarChangeListener sbLis = new OnSeekBarChangeListener() {
		
		@Override
		public void onStopTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onStartTrackingTouch(SeekBar seekBar) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			// TODO Auto-generated method stub
			ChangeContentFont(seekBar.getProgress());
		}
	};
	
	//
	private float contentFontSize = 18f;
	private void ChangeContentFont(int fontSize)
	{
		float expandFontSize = fontSize / 10;
		mContent.setTextSize(contentFontSize + expandFontSize); 	
		Log.i("KeaneWang", String.valueOf(expandFontSize));
	}
}

